<?php
/**
 * 
 * 问题库管理
 * @author ChunYang.Jiang<chunyang@staff.sina.com.cn>
 * @copyright sina
 * @version $Id$
 *
 */
class _Subject extends Controller
{
	public function add()
	{
		$this->display('Subject/add.html');
	}
	
	public function doAdd()
	{
		if (!$_POST['suveryid']){
			Util::msgRedirect('suveryid出错！');
		}else {
			$subject['suveryid'] = $_POST['suveryid'];
		}
		if (!$_POST['priorty']){
			Util::msgRedirect('题目序号没有！');
		}else {
			$subject['priorty'] = $_POST['priorty'];
		}
		if (!$_POST['type']){
			Util::msgRedirect('题目类型选择错误！');
		}else {
			$type = $_POST['type'];
			if ($type == "单选"){
				$type = "single";
			}elseif ($type == "多选"){
				$type = "multi";
			}elseif ($type == "填空"){
				$type = "fill";
			}elseif ($type == "问答"){
				$type = "qa";
			}elseif ($type == "组合"){
				$type = "assem";
			}elseif ($type == "分隔"){
				$type = "separator";
			}elseif ($type == "自定义内容"){
				$type = "customize";
			}else {
				Util::msgRedirect('没有该题型!');
			}
			$subject['type'] = $type;
		}
		if (!$_POST['topic']){
			Util::msgRedirect('题目主题未定义！');
		}else {
			$subject['topic'] = $_POST['topic'];
		}
		if (!$_POST['memo']){
			Util::msgRedirect('请填写memo备注！');
		}else {
			$subject['memo'] = $_POST['memo'];
		}
		$subject['additional'] = 'fauhuhrughrghur';
		$result = SubjectModule::add($subject);
		if (!$result){
			Util::msgRedirect('添加题目失败！', '/Admin/Subject');
		}
	}
	
	public function Show()
	{
		$total = 0;
		$pageSize = 10;
		$page = isset($_GET['page']) && $_GET['page'] && $_GET['page']>0 ? intval($_GET['page']) : 1;
		$pageStart = ($page-1) * $pageSize;
		$subjectList = SubjectModule::getSubject('1', $pageStart, $pageSize, $total);
		Util::page($total, $pageSize, $this->tpl);
		$this->assign('subjectList', $subjectList);
		$this->display('Subject/Show.html');
	}
	
	public function edit()
	{
		
	}
	

}